#include "WindowUtils.h"
#include <QApplication>
#include <QDesktopWidget>

// 将子窗口移动到父窗口的中央，偏上四分之一处
void WindowUtils::moveWindowToParentCenterTopQuarter(QWidget *childWindow, QWidget *parentWindow) {
    if (parentWindow) {
        QRect parentGeometry = parentWindow->geometry();
        int newX = parentGeometry.x() + (parentGeometry.width() - childWindow->width()) / 2;
        int newY = parentGeometry.y() + parentGeometry.height() / 4 - childWindow->height() / 2;
        childWindow->move(newX, newY);
    } else {
        moveWindowToTopQuarter(childWindow);
    }
}

// 将窗体移动到屏幕中央
void WindowUtils::moveToCenter(QWidget *window) {
    QRect screenGeometry = QApplication::desktop()->screenGeometry();
    int newX = (screenGeometry.width() - window->width()) / 2;
    int newY = (screenGeometry.height() - window->height()) / 2;
    window->move(newX, newY);
}

// 将窗体调整到指定大小
void WindowUtils::resizeWindow(QWidget *window, int width, int height) {
    window->resize(width, height);
}

// 将窗体移动到指定的x, y坐标
void WindowUtils::moveWindow(QWidget *window, int x, int y) {
    window->move(x, y);
}

// 将窗体放置到屏幕四分之一的上部
void WindowUtils::moveWindowToTopQuarter(QWidget *window) {
    QRect screenGeometry = QApplication::desktop()->screenGeometry();
    int newX = (screenGeometry.width() - window->width()) / 2;
    int newY = screenGeometry.height() / 4 - window->height() / 2;
    window->move(newX, newY);
}
